package com.joinlabs.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

@Configuration
public class CustomExceptionResolver implements HandlerExceptionResolver{


	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		
		ModelAndView mv = new ModelAndView();
		
		if(ex instanceof java.lang.ArithmeticException){
			mv.setViewName("/error/error1");
		}else if(ex instanceof java.lang.NullPointerException){
			mv.setViewName("/error/error2");
		}
		
		mv.addObject("error", ex.toString());
		
		return mv;
	}

}
